#include "UdpServer.hpp"
#include "dictServer.hpp"
#include <iostream>

std::string defaultFun(const std::string& str)
{
    LOG(LogLevel::DEBUG) << "client info:" << str;
    std::string ans = "success for send info:";
    return ans += str;
}

int main(int argc, char* args[])
{
    if (argc != 2)
    {
        std::cerr << "格式错误，正确格式: ./UdpServer port" << std::endl;
        return 1;
    }

    ENABLE_CONSOLE_LOG_STRATEGY();

    uint16_t port = std::stoi(args[1]); 

    DictServer dict;
    dict.getWords();
    
    UdpServer server(port, [&dict](const std::string& word, const InetAddr& client)->std::string
        { return dict.translate(word, client); });

    LOG(LogLevel::DEBUG) << "server init";    
    server.init();
    LOG(LogLevel::DEBUG) << "server start";    
    server.start();

    return 0;
}